package com.community.web.master.controller;


import com.community.common.result.Result;
import com.community.model.entity.Area;
import com.community.web.master.domain.dto.AreaDto;
import com.community.web.master.domain.dto.GoodsDto;
import com.community.web.master.domain.dto.PageAreaDto;
import com.community.web.master.domain.vo.PageResult;
import com.community.web.master.service.IAreaService;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李晶
 * @since 2024-07-02
 */
@RestController
@RequestMapping("/master/area")
@Api(tags = "区域")
@Slf4j
public class AreaController {
    @Autowired
    IAreaService iAreaService;
    @GetMapping("/pageQuery")
    @ApiOperation("分页查询")
    public Result<PageResult> pageQuery(PageAreaDto pageAreaDto){
        log.info("分页查询"+pageAreaDto);
        PageResult pageResult = iAreaService.pageQuery(pageAreaDto);
        return Result.success(pageResult);
    }
    @GetMapping
    @ApiOperation("获取所有区域")
    public Result<List<Area>> list(){
        log.info("获取所有区域");
        return Result.success(iAreaService.list());
    }

    @PostMapping
    @ApiOperation("新增区域")
    public Result add(AreaDto areaDto){
        log.info("新增地区"+areaDto);
        iAreaService.addArea(areaDto);
        return Result.success();

    }

    @PutMapping
    @ApiOperation("修改区域")
    public Result update(@RequestBody AreaDto areaDto){
        log.info("修改区域"+areaDto);
        iAreaService.updateArea(areaDto);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除区域")
    public Result delete(@PathVariable Integer id){
        log.info("删除区域"+id);
        iAreaService.deleteArea(id);
        return Result.success();
    };
}
